/*
 * binarySearchCircle.cpp
 *
 *  Created on: Sep 6, 2012
 *      Author: jeffrey
 */
#include<iostream>
using namespace std;
class BinarySearchCircle {
public:
	static int search(int array[], int n, int key) {
		if (array == NULL)
			return -1;
		return binarySearchCircle(array, 0, n - 1, key);

	}
	static int binarySearchCircle(int array[], int s, int e, int key) {
		while (s <= e) {
			int mid = (s + e) / 2;
			if (array[mid] == key)
				return mid;
			if (array[s] < array[mid]) {
				if (key > array[mid] || key < array[s])
					s = mid + 1;
				else
					e = mid - 1;
			} else {
				if (key < array[mid] || key > array[e])
					e = mid - 1;
				else
					s = mid + 1;
			}
		}
		return -1;
	}
};


